package com.easy.controller;

import com.easy.bean.Inventory;
import com.easy.common.CommonResult;
import com.easy.dao.IInventoryDao;
import com.easy.dao.IIsShelfDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Ayer
 */
@RestController
@RequestMapping("/inventory")
public class IsShelfController {
    @Autowired
    IIsShelfDao dao;

    @GetMapping("/isshelf")
    public CommonResult getShelfInventory() {
        List<Inventory> list = dao.getShelfInventory();
        return CommonResult.success(list);
    }
    @DeleteMapping("/isshelf/{product_id}")
    public CommonResult isShelfInventory(@PathVariable String  product_id){
        int count = dao.isShelfInventory(product_id);
        if (count > 0) {
            return CommonResult.success(count);
        }else {
            return CommonResult.fail();
        }
    }

    @DeleteMapping("/shelfdel/{product_id}")
    public CommonResult shelfDelInventory(@PathVariable String  product_id){
        int count = dao.shelfDelInventory(product_id);
        if (count > 0) {
            return CommonResult.success(count);
        }else {
            return CommonResult.fail();
        }
    }


}
